const path = require('path')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')

module.exports = {
  // build编译后不生成资源MAP文件
  productionSourceMap: false,
  //开发服务,build后的生产模式还需nginx代理
  devServer: {
    open: false, //运行后自动打开浏览器
    port: process.env.VUE_APP_PORT //挂载端口
    // proxy: {
    //   '/api': {
    //     target: 'http://localhost:3001/api',
    //     ws: true,
    //     pathRewrite: {
    //       '^/api': '/'
    //     }
    //   }
    // }
  },
  chainWebpack: (config) => {
    config.resolve.alias.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js')
    // 配置htmlWebpackPlugin
    config.plugin('html').tap((args) => {
      args[0].title = 'Niu Admin'
      return args
    })
  },
  configureWebpack: {
    plugins: [
      AutoImport({
        // resolvers: [ElementPlusResolver()],
        // 解决el-loading 指令方式style加载报错
        resolvers: [ElementPlusResolver({ importStyle: false })]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      })
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    }
  }
}
